home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / mep1 / Samples / Programs / tail.icn < prev    next >
Encoding:
Text File  |  1989-05-09  |  952 b   |  38 lines  |  [TEXT/PICN]

  1. ############################################################################
  2. #
  3. #  tail.icn
  4. #  
  5. #     This program writes the last lines of a file to the Interactive
  6. #  window, or to a file if Program Output has been redirected.  The user
  7. #  is prompted with a Get File dialog and the program continues to
  8. #  process files until the user selects Cancel in a file dialog.
  9. #  
  10. #  Option:
  11. #  
  12. #       n    Number of lines to write.  The default is 10.
  13. #
  14. ############################################################################
  15.  
  16. procedure main(args)
  17.     local i, infile, tail, name
  18.     
  19.     i := integer(args[1]) | 10
  20.     while name := getfile("File?") do {
  21.         close(\infile)
  22.         infile := open(name) | {
  23.             write(&errout,"*** cannot open ",name)
  24.             next
  25.             }
  26.         tail := []
  27.         every 1 to i do {
  28.             put(tail,read(infile)) | {
  29.                 while write(get(tail))            # short file
  30.                 exit()
  31.                 }
  32.              }
  33.         while put(tail,read(infile)) do
  34.             get(tail)
  35.         while write(get(tail))
  36.         }
  37. end
  38.